package com.copymd;

import cn.hutool.core.util.StrUtil;
import org.junit.Test;

import java.io.*;
import java.util.Arrays;

public class CopyMD {

    @Test
    public void getHTMLnote() {

    }


    public void excute(String path) throws Exception {
        File dirs = new File(path);
        for (String s : dirs.list()) {
            File file = new File(path + "\\" + s);
            if (file.isDirectory()) {
                excute(path + "\\" + s);
            }
            if (!file.isDirectory() && file.getName().endsWith("md")) {
                copy(path + "\\" + s, s);
            }

        }


    }


    public void copy(String path, String file) throws Exception {
        //需求：读取文件中的数据，排序后再次写到本地文件
        //分析：
        //1.要把文件中的数据读取进来。
        BufferedReader br = new BufferedReader(new FileReader(path));
        //输出流一定不能写在这里，因为会清空文件中的内容
        BufferedWriter bw = new BufferedWriter(new FileWriter("E:\\BaiduNetdiskDownload\\02-Java课V12.5版本172G\\12-17Java精英进阶阶段（赠送）\\14-第十四阶段-智牛股\\讲义-md\\" + file));

        String line = null;
        while ((line = (br.readLine())) != null) {

            if (StrUtil.hasEmpty(line)) {
                continue;
            }
            if (line.contains("```")) {
                bw.write(line.trim());
            } else {
                bw.write(line);
            }

            bw.newLine();
        }
        bw.close();
        br.close();
    }

    @Test
    public void excuteCMD() {
        Runtime runtime = Runtime.getRuntime();
        File file = new File("F:\\BaiduNetdiskDownload\\博学谷人工智能就业课（尊享无忧）\\00：人工智能极速就业班课程资料\\阶段一python基础资料\\day01\\03-笔记");
        try {
            Process exec = runtime.exec("mdtools.bat", null, file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
